package cn.tips.dmp.supports.jpa;

import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * @author pkb
 */
@Data
public class PageParamsDTO {
    private Integer currentPage;
    private Integer pageSize;

    public Pageable getPageable() {
        assert this.currentPage > 0;

        assert this.pageSize > 0;

        return PageRequest.of(this.currentPage - 1, this.pageSize);
    }

    public Pageable getPageableWithSort(Sort sort) {
        assert this.currentPage > 0;

        assert this.pageSize > 0;

        return PageRequest.of(this.currentPage - 1, this.pageSize, sort);
    }

    public PageParamsDTO() {
    }

}
